function [ptPedal,pedalVec,angle] = CalVerticalVec(pt,ptStart,ptEnd)
ptX=pt(1);
ptY=pt(2);
ptZ=pt(3);
ptStartX=ptStart(1);
ptStartY=ptStart(2);
ptStartZ=ptStart(3);
ptEndX=ptEnd(1);
ptEndY=ptEnd(2);
ptEndZ=ptEnd(3);
%用向量求直线外的点在直线上的投影
d=0;
vtDirectionX = ptEndX - ptStartX; 
vtDirectionY = ptEndY - ptStartY;
vtDirectionZ = ptEndZ - ptStartZ;

% 一定要单位化，下面求d时就不需要分母了
dLength = sqrt(vtDirectionX^2 + vtDirectionY^2 + vtDirectionZ^2);
vtDirectionX = vtDirectionX / dLength;
vtDirectionY = vtDirectionY / dLength;
vtDirectionZ = vtDirectionZ / dLength;

% 垂足与pt的向量
x1 = ptStartX + vtDirectionX * d - ptX;
y1 = ptStartY + vtDirectionY * d - ptY;
z1 = ptStartZ + vtDirectionZ * d - ptZ;

% 直线的向量
x2 = vtDirectionX;
y2 = vtDirectionY;
z2 = vtDirectionZ;

% vt1 * vt2 = 0;%导出d
% x1 * x2 + y1 * y2 + z1 * z2 = 0;
d = ptX * vtDirectionX - ptStartX * vtDirectionX + ptY * vtDirectionY - ptStartY * vtDirectionY + ptZ * vtDirectionZ - ptStartZ * vtDirectionZ;

% 求出垂足
ptPedalX = ptStartX + vtDirectionX * d;
ptPedalY = ptStartY + vtDirectionY * d;
ptPedalZ = ptStartZ + vtDirectionZ * d;
ptPedal=[ptPedalX;ptPedalY;ptPedalZ];
pedalVec=ptPedal-pt;
if(ptPedalX==0)
    angle=90;
else
    angle = atan(ptPedalY/ptPedalX)/pi*180;
end

